package com.lemon.smartsafety.ui.fragment.mine;

import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.ldzs.recyclerlibrary.Mode;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.entity.bind.BindInfoExtVo;
import com.lemon.smartsafety.http.service.UserServices;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.ui.adapter.apps.MyAppsAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by Cooliean on 16/4/7.
 */
public class MyAppFragment extends BasePullToRefreshFragment<BindInfoExtVo, List<BindInfoExtVo>> implements RecyclerTClickListener<BindInfoExtVo> {

    public Toolbar mToolBar;

    @Nullable
    public TextView mMainTitle;


    @Override
    public boolean goRefreshOnCreate() {
        if (mDataList != null && mDataList.size() != 0) {
            return false;
        }
        return true;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.fragment_refresh_tool_bar;
    }

    @Override
    protected void initViews() {
        super.initViews();
        mToolBar = getViewById(R.id.toolbar);
        mMainTitle = getViewById(R.id.main_title);
        initToolbar();
        mPullToRefreshRecyclerView.setRefreshMode(Mode.PULL_FROM_START);
    }


    protected void initToolbar() {
        ((AppCompatActivity) getActivity()).setSupportActionBar(mToolBar);
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
        mMainTitle.setText("我的应用");
        ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("");
        mToolBar.setNavigationIcon(R.mipmap.ic_menu_white);

    }

    public void setTitle(String title) {
        mMainTitle.setText(title);
        ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("");
    }


    @Override
    public LemonRcvAdapter<BindInfoExtVo> getLemonAdapter() {
        return new MyAppsAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return EventTag.TAG_MY_APPS;
    }

    @Override
    public void onLoadMore() {

    }

    @Override
    public void onPullRefresh() {
        UserServices.init().getMyApps();
    }

    @Override
    public void httpRefresh(List<BindInfoExtVo> data) {
        super.httpRefresh(data);
        mPullToRefreshRecyclerView.setRefreshMode(Mode.PULL_FROM_START);
    }

    @Override
    public void onItemClick(BindInfoExtVo data, int position) {

    }
}
